package com.mianshi;

public class wuba3 {
    public static void main(String[] args) {
        int num = StringSplit("bbbb");
        System.out.println(num);
    }

    public static int StringSplit (String str) {
        // write code here
        int ans = 0;
        int len = str.length();
        char[] arr = str.toCharArray();
        ans += arr[0] == 'a' ? 1:0;
        for(int i = 1; i < len; i++){
            if(arr[i] == 'b'){
                ans++;
            }
        }
        int temp = ans;
        for(int i = 1; i < len-1; i++){
            if(arr[i] == 'a'){
                temp++;
            } else {
                temp--;
            }
            ans = Math.max(ans, temp);
        }
        return ans;
    }
}
